package org.rpgmapper.view;

import org.rpgmapper.R;
import org.rpgmapper.bo.Stat;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.NumberPicker.OnValueChangeListener;

public class StatView extends FrameLayout {

	private Stat stat;
	private PickerView picker;
	private OnPickerValueChangeListener onPickerValueChangeListener;
	
	public StatView(Context context) {
		super(context);
		init();
	}
	public StatView(Context context, Stat stat, OnPickerValueChangeListener onPickerValueChangeListener) {
		super(context);
		this.stat = stat;
		this.onPickerValueChangeListener = onPickerValueChangeListener;
		init();
	}
	public StatView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}
	public StatView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	private void init() {
		LayoutInflater.from(getContext()).inflate(R.layout.stat, this);
		((TextView)findViewById(R.id.label)).setText(stat.name());
		picker = (PickerView)findViewById(R.id.pickerView);
		picker.setTag(stat);
		picker.setOnPickerValueChangeListener(onPickerValueChangeListener);
	}
	
	public void setValue(int value) {
		picker.setValue(value);
	}
}
